package com.txd.mofa.shoucang.fgt;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;

import androidx.fragment.app.Fragment;

import com.kongzue.baseframework.interfaces.Layout;
import com.txd.mofa.R;
import com.txd.mofa.adapter.FragmentAdp;
import com.txd.mofa.base.BaseFgt;
import com.txd.mofa.net.NetUtils;
import com.txd.mofa.shouye.fgt.FaxingFgt;
import com.txd.mofa.view.HXLinePagerIndicator;
import com.txd.mofa.view.MyViewPager;
import com.txd.mofa.view.ScaleTransitionPagerTitleView;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.UIUtil;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

import java.util.ArrayList;
import java.util.List;

@Layout(R.layout.fgt_shoucang)
public class ShoucangFgt extends BaseFgt {

    MyViewPager viewpager;
    private MagicIndicator magicIndicator;

    private List<String> listTitle = new ArrayList<>();
    private List<Fragment> list = new ArrayList<>();



    public static ShoucangFgt newInstance() {

        Bundle args = new Bundle();

        ShoucangFgt fragment = new ShoucangFgt();
        fragment.setArguments(args);
        return fragment;
    }



    @Override
    public void initViews() {
        super.initViews();
        magicIndicator = findViewById(R.id.magic_indicator);
        viewpager = findViewById(R.id.viewpager);


        listTitle.add("我的收藏");
        listTitle.add("我的作品");

        list.add(ZoupinFgt.newInstance("1"));
        list.add(ZoupinFgt.newInstance("2"));

        FragmentAdp fragmentAdp = new FragmentAdp(getChildFragmentManager(), list, listTitle);
        viewpager.setAdapter(fragmentAdp);
        viewpager.setOffscreenPageLimit(list.size());

        CommonNavigator commonNavigator = new CommonNavigator(me);

        //true 选项卡均分父布局宽度。这种情况仅仅在选项卡较少且文字比较短时候合适
        //     如果文字很长，且选项卡很多，那么久会挤在一起密密麻麻，视觉上比较难看。
        //通常设置false。
        commonNavigator.setAdjustMode(false);

        commonNavigator.setAdapter(new CommonNavigatorAdapter() {
            @Override
            public int getCount() {
                return listTitle == null ? 0 : listTitle.size();
            }

            @Override
            public IPagerTitleView getTitleView(Context context, final int index) {
//                SimplePagerTitleView simplePagerTitleView = new SimplePagerTitleView(context);
                SimplePagerTitleView simplePagerTitleView = new ScaleTransitionPagerTitleView(context); //使用自定义
                simplePagerTitleView.setText(listTitle.get(index));
                simplePagerTitleView.setTextSize(19);
                simplePagerTitleView.setNormalColor(getResources().getColor(R.color.hui));
                simplePagerTitleView.setSelectedColor(getResources().getColor(R.color.huang));
                simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        viewpager.setCurrentItem(index);
                    }
                });

                return simplePagerTitleView;
            }

            @Override
            public IPagerIndicator getIndicator(Context context) {
                HXLinePagerIndicator indicator = new HXLinePagerIndicator(context);
                indicator.setMode(LinePagerIndicator.MODE_EXACTLY);
                indicator.setLineHeight(UIUtil.dip2px(context, 4));
                indicator.setLineWidth(UIUtil.dip2px(context, 20));
                indicator.setRoundRadius(UIUtil.dip2px(context, 3));

                indicator.setStartInterpolator(new AccelerateInterpolator());
                indicator.setEndInterpolator(new DecelerateInterpolator(2.0f));

                return indicator;
            }
        });

        magicIndicator.setNavigator(commonNavigator);

        ViewPagerHelper.bind(magicIndicator, viewpager);


    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    public void onLazyLoad() {

    }

    @Override
    public void setEvents() {

    }
}
